package com.smarthealthcare.discharge.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smarthealthcare.common.annotation.Log;
import com.smarthealthcare.common.core.controller.BaseController;
import com.smarthealthcare.common.core.domain.AjaxResult;
import com.smarthealthcare.common.enums.BusinessType;
import com.smarthealthcare.discharge.domain.Discharge;
import com.smarthealthcare.discharge.service.IDischargeService;
import com.smarthealthcare.common.utils.poi.ExcelUtil;
import com.smarthealthcare.common.core.page.TableDataInfo;

/**
 * 出院管理Controller
 * 
 * @author ruoyi
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/discharge/discharge")
public class DischargeController extends BaseController
{
    @Autowired
    private IDischargeService dischargeService;

    /**
     * 查询出院管理列表
     */
    @PreAuthorize("@ss.hasPermi('discharge:discharge:list')")
    @GetMapping("/list")
    public TableDataInfo list(Discharge discharge)
    {
        startPage();
        List<Discharge> list = dischargeService.selectDischargeList(discharge);
        return getDataTable(list);
    }

    /**
     * 导出出院管理列表
     */
    @PreAuthorize("@ss.hasPermi('discharge:discharge:export')")
    @Log(title = "出院管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Discharge discharge)
    {
        List<Discharge> list = dischargeService.selectDischargeList(discharge);
        ExcelUtil<Discharge> util = new ExcelUtil<Discharge>(Discharge.class);
        util.exportExcel(response, list, "出院管理数据");
    }

    /**
     * 获取出院管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('discharge:discharge:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dischargeService.selectDischargeById(id));
    }

    /**
     * 新增出院管理
     */
    @PreAuthorize("@ss.hasPermi('discharge:discharge:add')")
    @Log(title = "出院管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Discharge discharge)
    {
        return toAjax(dischargeService.insertDischarge(discharge));
    }

    /**
     * 修改出院管理
     */
    @PreAuthorize("@ss.hasPermi('discharge:discharge:edit')")
    @Log(title = "出院管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Discharge discharge)
    {
        return toAjax(dischargeService.updateDischarge(discharge));
    }

    /**
     * 删除出院管理
     */
    @PreAuthorize("@ss.hasPermi('discharge:discharge:remove')")
    @Log(title = "出院管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dischargeService.deleteDischargeByIds(ids));
    }

}
